import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;


public class modificaXmls extends JFrame implements ActionListener  {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * @param args
	 * 
	*/
	
	public JButton b1;
	public JButton b2;
	public JPanel p;
	public JFrame f;
	public JLabel l;
	public JLabel l2;
	public JTextField origem;
	public JTextField destino;
	public JFileChooser file;
	
	
	public modificaXmls(){
		
		
		// Janela principal
		f = new JFrame("Modificador XMLS - By David Coelho");
		p = new JPanel();
		
		l = new JLabel("Digite o caminho do arquivo de origem");
		p.add(l);
		
		file = new JFileChooser();
	
		origem = new JTextField("c:",30);
		p.add(origem);
		
		b2 = new JButton("Procurar Arquivo");
		b2.addActionListener(this);
		b2.setFont(new Font("Arial",Font.PLAIN, 14));
		p.add(b2);
		
	//	l2 = new JLabel("Diretorio Destino");
		//l2.setBounds(new Rectangle(30,30,80,90));
	//	p.add(l2);
		
		destino = new JTextField("c:",30);
		p.add(destino);
		
		b1 = new JButton("Modificar XML");
		b1.addActionListener(this);
		b1.setFont(new Font("Arial",Font.PLAIN, 15));
		p.add(b1);
		
		f.setContentPane(p);		
		
	//	p.setBounds(0,0,560,400);

		f.setSize(450, 180);
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
		f.setResizable(false);
		
		}
	
	public static void main(String[] args) {
		
		new modificaXmls();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
	
		if (e.getSource() == b1){
				 try {
					 
					new	trataArquivo(origem.getText(),destino.getText() + file.getSelectedFile().getName());
					
					JOptionPane.showMessageDialog(null,  
			    	         "Arquivo Modificado com Sucesso !"
			    			 ,"Aviso", JOptionPane.INFORMATION_MESSAGE);
					
				} catch (UnsupportedEncodingException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (FileNotFoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
		
		} else if (e.getSource() == b2){
			
			FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivo Xml", "xml");
		    file.addChoosableFileFilter(filter);
			
		    
			
			int retorno = file.showOpenDialog(null);

			if (retorno==JFileChooser.APPROVE_OPTION){
				
				   origem.setText(file.getSelectedFile().getAbsolutePath());
				  		   
			}
			}
		
		
	}

	}



